
{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-body layui-row ">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>微信账号管理</legend>
                <blockquote class="layui-elem-quote">
                    测试号二维码: 请不要把此测试公众号状态关闭，否则其他微信体验功能可能会受到影响
                    已部署到自己线上可以删除该公众号！
                    <img width="120" src="__WECHAT__/images/my.jpg" alt="二维码">
                </blockquote>
            </fieldset>
        </div>
    </div>

    <div class="layui-card">
        <div class="layui-card-header" style="line-height: 55px;">
            <div class="layui-btn-container do_btn">
                <!--按钮区-->
                <button class="layui-btn layui-btn-sm" data-type="add"><i class="layui-icon"></i>添加公众号</button>
                <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="reload"><i class="fa fa-refresh"></i> 刷新</button>
            </div>
        </div>
        <div class="layui-card-body">

            <!--表格区-->
            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>


{/block}


{block name="js"} <!--js处理区-->

<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="qr">
    {{d.qr}}
</script>
<script type="text/html" id="logo">
    {{d.logo}}
</script>

<script type="text/html" id="create_time">
    {{layui.util.toDateString(d.create_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>

<!--模板-->
<script type="text/html" id="operationTpl">
    {:widget('common/forms/Editbtn',array('编辑账号信息'))}
    {:widget('common/forms/Delbtn',array('删除账号',2))}
</script>




<script>

    layui.use(['element', 'table', 'form', 'jquery', 'lucky'], function () {
        let element = layui.element;
        let form = layui.form;
        let table = layui.table;
        let $ = layui.jquery;
        let lucky=layui.lucky;

        form.render();

        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('index')}",
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:30
                ,limits:[10,20,30,50]
            },
            //height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            method: 'post',
            cols: [[
                {field: 'id', title: 'ID', width: 80, fixed: true, sort: true},
                {field: 'wxname', title: '公众号名字', width: 120,event:"search"},
                {field: 'origin_id', title: '公众号原始ID', width: 120,},
                {field: 'app_id', title: 'appid', width: 120, },
                {field: 'app_secret', title: 'appsecret', width: 120, },
                {field: 'w_token', title: '微信对接token', width: 120,},
                {field: 'qr', title: '二维码', width: 120,templet:'#qr'},
                {field: 'logo', title: 'logo', width: 120,templet:'#logo'},
                {field: 'type_name', title: '类型', width: 120, },
                {field: 'status', title: '接入状态', width: 180,sort:true, templet:'#status'},
                {field: 'create_time', title: '添加时间', width: 180,templet:'#create_time'},
                {fixed: 'right',templet: '#operationTpl', width: 100, align: 'center', title: '操作'}
            ]],
            done: function (res) {
                layer.closeAll('loading');
            }
        });

        form.on('switch(status)', function(obj){
            let _id=parseInt(obj.value);
            lucky.Form_Ajax("{:url('state')}",{id:_id},"table_id");
        });



        table.on('tool(tableFilter)', function (obj) {
            let data = obj.data;
            let _id=parseInt(data.id);
            let layEvent = obj.event;
            if(layEvent==="edit"){
                //alert(_id);
                let urls="/wechat/wechat/edit/id/"+_id;
                lucky.CreateForm("编辑微信账号",'60%','80%',urls,"table_id");

            }else if(layEvent==="del"){
                lucky.Form_Ajax("{:url('delete')}",{id:_id},"table_id");

            }else if(layEvent==="search"){

                lucky.CreateSearch("table_id",{wexname:data.wxname}); //查询
                return false;
            }
        });


        let active = {
            add:function(){
                lucky.CreateForm("添加微信账号",'60%','80%',"{:url('add')}","table_id");
            },
            reload: function(){
                lucky.CreateReload("table_id");
            }

        };

        $('.do_btn .layui-btn').on('click', function(){
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >

{/block}
